package com.neu.servlet.ww;

import com.alibaba.fastjson.JSONObject;
import com.neu.service.klz.KindDaoService;
import com.neu.service.ww.OrderInfoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "OrderServlet",urlPatterns = "/OrderServlet.do")
public class OrderServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        String key=request.getParameter("key");
        KindDaoService kindDaoService=new KindDaoService();
        List<Map<String,Object>> kindList=kindDaoService.dofindByKname();
        HttpSession session=request.getSession();
        session.setAttribute("kindList",kindList);
        OrderInfoService orderInfoService=new OrderInfoService();
        List<Map<String,Object>> tenList=orderInfoService.doFindOrderInfoTen();
        session.setAttribute("tenList",tenList);
        String json=JSONObject.toJSONString(tenList);
        System.out.println(json);
        PrintWriter pw=response.getWriter();
        pw.write(json);
        pw.close();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
